package com.gulimall.search.thread;

import org.apache.tomcat.jni.Thread;

import java.util.concurrent.*;
import java.util.function.BiConsumer;
import java.util.function.Function;

public class TestThread {

//        Executors.newCachedThreadPool()  //缓存 可大可小
//        Executors.newSingleThreadExecutor()   //单个线程
//        Executors.newFixedThreadPool()        //固定线程数量

    public static ExecutorService executors = Executors.newFixedThreadPool(10);


    public static void main(String[] args) throws ExecutionException, InterruptedException {

//        System.out.println("--------------------------------------");
//        CompletableFuture future = CompletableFuture.supplyAsync(() -> {
//            System.out.println(Thread.currentThread().getName() + "\t completableFuture");
//            int i = 10 / 0;
//            return 1024;
//        }, executors).whenComplete((u, t) -> {
//            System.out.println("-------o=" + u.toString() + "==========" + t);
//
//        }).exceptionally(throwable -> {
//            return 12;
//        });

//        CompletableFuture future = CompletableFuture.supplyAsync(() -> {
//            System.out.println(Thread.currentThread().getName() + "\t completableFuture");
//            int i = 10 / 0;
//            return 1024;
//        }, executors).handle((u, t) -> {
//            System.out.println(u + 2);
//            if (t != null) {
//                return 0;
//            }
//            return 0;
//        });

//
//        CompletableFuture future = CompletableFuture.supplyAsync(() -> {
//            System.out.println(Thread.currentThread().getName() + "\t completableFuture");
//            int i = 10 / 0;
//            return 1024;
//        }, executors).


        CompletableFuture.supplyAsync(() -> {
            return 12;
        }, executors);


        System.out.println("+====================================================");
    }
}
